package com.liuqing.www.phone.server.底层消息;

import org.xsocket.connection.INonBlockingConnection;

/**
 * @author kevinbian E-mail: langzibian@yahoo.com.cn
 * @version 创建时间：2011-4-29 下午03:16:11
 * 
 */
public class DataSender  implements Runnable{
	
	
	INonBlockingConnection nbc ;
	
	byte[] sendHeader = null ;
	byte[] sendPack = null ;
	
	public DataSender(INonBlockingConnection nbc , byte[] sendPack) {
		this.nbc = nbc ;
		this.sendPack = sendPack ;
		Thread thread = new Thread(this);
		thread.start() ;
	}
	
	/*public DataSender(INonBlockingConnection nbc , byte[] sendHeader, byte[] sendPack) {
		this.nbc = nbc ;
		this.sendPack = sendPack ;
		this.sendHeader = sendHeader ;
		Thread thread = new Thread(this);
		thread.start() ;
	}*/
	
	public void send() {
		try {
			if(nbc == null){
				throw new Exception("INonBlockingConnection is null") ; 
			}
			if(sendHeader != null){
				this.nbc.write(sendHeader) ;
			}
			if(sendPack != null){
				this.nbc.write(sendPack) ;
				System.out.println("*****发送到时间*********id"+nbc.getId()+"  "+System.currentTimeMillis()+" "+sendPack.length);
			}
			this.nbc.flush() ;
		} catch (Exception e) {
			e.printStackTrace() ;
		}
	}
//	public 
	@Override
	public void run() {
		send() ;
	}
	
	
}
